package top.glkj.hms.entity;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.*;
import java.util.List;

/**
 * @author : xgl
 * @version : 0.0.1
 * @date :2020/12/24 22:21
 * 地址区域
 */
@Entity
@Table(name = "hms_area_address")
public class AreaAddress extends BaseEntity {
    /**
     * 酒店名称
     */
    @Column(name = "hotel_name")
    public String hotelName;
    /**
     * 酒店联系电话
     */
    @ElementCollection
    @CollectionTable(name = "hms_area_tels")
    @Column(name = "hms_area_tel")
    public List<String> tel;
    /**
     * 酒店地址
     */
    public String address;
    /**
     * 酒店房源
     */
    @Fetch(FetchMode.SUBSELECT)
    @ManyToMany(targetEntity = Room.class,cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(name = "hms_area_address_rooms",
            //当前对象在中间表中的外键
            joinColumns = {@JoinColumn(name = "area_address_id", referencedColumnName = "id")},
            //对方对象在中间表中的外键
            inverseJoinColumns = {@JoinColumn(name = "room_id", referencedColumnName = "id")}
    )
    public List<Room> roomList;
    /**
     * 空房间
    @Transient
    public List<Room> emptyRooms;
     */
    /**
     * 房源类型
     */
    @Fetch(FetchMode.SUBSELECT)
    @ManyToMany(targetEntity = RoomType.class,cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(name = "hms_area_address_room_types",
            //当前对象在中间表中的外键
            joinColumns = {@JoinColumn(name = "area_address_id", referencedColumnName = "id")},
            //对方对象在中间表中的外键
            inverseJoinColumns = {@JoinColumn(name = "room_type_id", referencedColumnName = "id")}
    )
    public List<RoomType> roomTypeList;
    /**
     * 活动
     */
    @Fetch(FetchMode.SUBSELECT)
    @ManyToMany(targetEntity = Activity.class,cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinTable(name = "hms_area_address_activities",
            //当前对象在中间表中的外键
            joinColumns = {@JoinColumn(name = "area_address_id", referencedColumnName = "id")},
            //对方对象在中间表中的外键
            inverseJoinColumns = {@JoinColumn(name = "activity_id", referencedColumnName = "id")}
    )
    public List<Activity> activityList;
}
